[GH-1996] Create object of S2Geography, and implement Point/Polyline/PolygonGeography with its encoder/decoder#1992
Conversation
|
@ZhuochengShang great work. Please create a GitHub issue and link the PR to that issue using [GH-XXXX] |
|
Great work @ZhuochengShang . It is great to have a working PR that shows the progress. But when it is ready, we'd like to break it into a sequence of small PRs. This will make the review process easier. |
|
Please also update the title of this PR to |
|
Thank you for this work so far! Just a note that if you (or Kristin or Jia) run across anything that doesn't make sense or is sub-optimial in the C++ version of S2Geography to let me know! |
- Import org.datasyslab s2-geometry-library - Clean up S2Geography abstract design - Update Encode/Decode inside each kind of geography
- Adding back EncodeTagged in S2Geography - Let each geography type calls its own encode / decode function - Change to use Kyro UnsafeInput and UnsafeOutput
Kontinuation
left a comment
There was a problem hiding this comment.
The overall structure looks good. There are some additional comments mostly for the decoding part.
I also suggest that we add more comprehensive tests for encoding and decoding of geography objects. For instance, includeCovering option has not been tested for now. Adding a utility test function for round-trip encoding/decoding any geography objects and validate their equality would help writing such tests a lot.
| public class PolylineGeography extends S2Geography { | ||
| private static final Logger logger = Logger.getLogger(PolylineGeography.class.getName()); | ||
|
|
||
| private final List<S2Polyline> polylines; |
There was a problem hiding this comment.
We define PolylineGeography to contain a list of S2Polylines, which is different from the C++ version. I think this is a reasonable change, as it makes distinguishing between POLYGON and MULTIPOLYGON much easier as long as we ensure that each S2Polyline only contains one polygon. WDYT @paleolimbot
There was a problem hiding this comment.
I believe that Polyline in C++ is also a std::vector<S2Polyline>, but you're correct that the polygon is defined this way.
Paul (PostGIS) complained about this too, mostly because some multipolygons don't roundtrip through WKB/T/JTS. I've personally found it easier to keep the S2-centric structure since a lot of the time internally it doesn't matter. Either way is fine!
There was a problem hiding this comment.
Pull Request Overview
Adds support for S2Geography objects (Point, Polyline, Polygon) with Kryo‐based encoding/decoding and corresponding round‐trip tests, and updates the S2 library dependency.
- Introduce
S2Geographybase class andPointGeography,PolylineGeography,PolygonGeographysubclasses with encode/decode logic - Add
TestHelperutility and unit tests for each geography type (round‐trip and covering assertions) - Update
pom.xmlto use the forkedorg.datasyslab:s2-geometry-libraryand shade Google’s S2 package
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java | Base abstract class and encoding/decoding machinery |
| common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java | Implements point encoding/decoding and optimized compact path |
| common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java | Implements polyline path handling and (de)serialization |
| common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java | Implements single‐loop polygon handling and (de)serialization |
| common/src/test/java/org/apache/sedona/common/S2Geography/TestHelper.java | Utility for verifying round‐trip correctness and coverings |
| common/src/test/java/org/apache/sedona/common/S2Geography/PointGeographyTest.java | Point geography unit tests |
| common/src/test/java/org/apache/sedona/common/S2Geography/PolylineGeographyTest.java | Polyline geography unit tests |
| common/src/test/java/org/apache/sedona/common/S2Geography/PolygonGeographyTest.java | Polygon geography unit tests |
| common/pom.xml | Swap in the forked S2 library and add shading for Google S2 |
Comments suppressed due to low confidence (1)
common/src/test/java/org/apache/sedona/common/S2Geography/TestHelper.java:83
- [nitpick] The error message uses a hard-coded index '1' for both polygon and loop, but you are checking loop zero. Consider using the actual loop index (e.g., '0') or dynamically inserting the index to avoid confusion.
"Loop count mismatch in polygon[" + 1 + "]", pgOrig.numLoops(), pgDec.numLoops());
|
What is the status of this PR? |
Kontinuation
left a comment
There was a problem hiding this comment.
There are some minor issues related to the revised PolygonGeography. I think this PR is close to completion.
Kontinuation
left a comment
There was a problem hiding this comment.
Now it looks good to me. Thank you for your great work @ZhuochengShang
|
Awesome! |
…yline/PolygonGeography with its encoder/decoder (apache#1992) * Create object of S2Geography, and implement PoinGeography with its encoder/decoder * Add POLYLINE implementation on S2Geography * Add POLYGON implements on S2Geography * Match coding style * "Apply Spotless formatting to PolylineGeographyTest" * Redesign of S2Geography - Import org.datasyslab s2-geometry-library - Clean up S2Geography abstract design - Update Encode/Decode inside each kind of geography * clean up unnecessary files in current branch * Refine design of EncodeTagged in S2Geography - Adding back EncodeTagged in S2Geography - Let each geography type calls its own encode / decode function - Change to use Kyro UnsafeInput and UnsafeOutput * Modify encoder() and add new test cases * clean up code of encode and clarify comments * Update POLYGON to only take one polygon * Remove S2Regionwrapper & S2Shapewrapper * clean up minor issue * resolve minor issue with PolygonGeography
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject.What changes were proposed in this PR?
The first step of porting https://github.com/paleolimbot/s2geography, ported S2Geography base class and 3 sub types.
How was this patch tested?
Added unit tests.
Did this PR include necessary documentation updates?